<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html >
	 <head>
 		<title>${title }</title>
 		 <link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/main.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchBtn.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchCondition.css" />
	    <!-- js -->
 		<script type="text/javascript" src="${ctx}/static/scripts/check_all.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/waiting.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/crud.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/util.js"></script>
		<script type="text/javascript" src="${ctx}/static/scripts/WdatePicker/WdatePicker.js"></script>
	</head>
  <body onload="init()">
		<form action="${ctx}/deviceParts/list" method="post">
  			<input type="hidden" name="RequestVerificationToken" value="${RequestVerificationToken}" />
			<div class="width_100 group_box">
				<div class="group_search width_100">
					<vvise:searchInput id="partsCode" name="p_partsCode" displayText="配件编号" />
					<vvise:searchInput id="partsName" name="p_partsName" displayText="配件名称" />
					<vvise:searchInput id="partsOper" name="p_partsOper" displayText="经办人" />
					<vvise:searchInput id="startDate" name="p_startDate" defVal="${startDate}" 
			                endId="endtDate" endName="p_endtDate" endDefVal="${endDate}"
			                type="time2" displayText="入库时间" dateFormat="yyyy-MM-dd"/>
               	 	<div class="clear_both"></div>
				</div>
				<vvise:funMenu menuId="${menuId}" />
			</div>
        </form>
        <div class="listFrame">
        	<iframe name="listFrame" id="listFrame" frameBorder="0"
				scrolling="auto" style="width: 100%;height:100%;"></iframe>
        </div>
	</body>
	<script type="text/javascript">
  		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
			//回车事件
		document.onkeydown = keyKistener;
		function keyKistener(e){
			e = e ? e:event;
			if(e.keyCode == 13){
				try{
					search();
				}catch(e){}
			}
		}
		function init(){
			set_iframe_h();
			$(window).resize(function(){
				set_iframe_h();
			});
			search();
			$('.easyui-combobox').combobox();
		}
		//设置ifream 高度
		function set_iframe_h(){
			var win_height  = $(window).height();
			var func_line_h = $('.group_box').outerHeight(true);
			var list_height = win_height - func_line_h;
			$('.listFrame').css('height',list_height-10);
		}
		function search(){
			waiting();
			document.forms[0].target = "listFrame";
			document.forms[0].submit();
		}
		
		function create(partsId){
			if(parent.isEmpty(partsId))
				partsId = "";
				
			var pp = parent;
			doCreate("仪器配件",pp.width1,380,"${ctx}/deviceParts/edit?partsId="+partsId);
		}
		
		function save(){
			var pp = parent;
			var editFrame = pp.winFrame;
			var partsId = editFrame.$('#partsId').val();
			var partsCode = editFrame.$('#partsCode').val();
			var partsNum = editFrame.$('#partsNum').val();
			
			if(!pp.validData("partsCode","请输入配件编号！"))
				return;
			
			if(!pp.validData("partsName","请输入配件名称！"))
				return;
			
			if(!pp.validData("partsSpec","请输入规格/型号！"))
				return;
			
			if(!pp.validData("partsNum","请输入入库数量！")){
				return;
			}else{
				var pattern = /^[0-9]*$/;
				if(!pattern.test(partsNum)){
					pp.alertMsg('入库数量只能输入正整数','warning');
					return;
				}
			}
			
			if(!pp.validData("storageTime","请选择入库时间！"))
				return;
			
			if(!pp.validData("partsOper","请输入经办人！"))
				return;
				
			var flag = executeAjaxBySync('${ctx}/deviceParts/checkName','partsCode='+partsCode+"&partsId="+partsId);
			if(flag == 'error'){
				pp.alertMsg('该配件编号已经存在，请重新输入','warning',function(){
					try{
					 	editFrame.$('#partsCode').focus();
				 	 }catch(e){}
				});
				return;
			}
			doSave("${ctx}/deviceParts/save",partsId);
		}
		
		function view(partsId){
			var pp = parent;
			doView("仪器配件",pp.width1,380,"${ctx}/deviceParts/edit?partsId="+partsId+"&view=view");
		}
		
		function removeF(){
			var pp = parent;
			var ids = "";
			var ecForm = listFrame.document.all.ec;
			if(!checkSelect(ecForm.id,true))
				return;
			ids = get_checkbox_values(ecForm.id,',');
			
			pp.confirmMsg("确定要删除吗？",function(){
				var urls = "${ctx}/deviceParts/delete";
			    var params = "partsIds="+ids;
			    executeAjax(urls,params,function(data){
				    if(data != 'error'){
				    	pp.$.messager.alert('操作提示', "操作成功！", "info",function(){
				    		listRefresh();
				    	});
					}else{
						pp.$.messager.alert('操作提示',"操作失败！","error");
					}
			    });
			});
		}
		
		
		/* 出库管理 */
		function outStore(){
			var pp = parent;
			var ecForm = listFrame.document.all.ec;
			if(!checkSelect(ecForm.id,false,""))
				return;
			
			var objs = ecForm.id;
			var obj;
			if(objs.length){
			     for(i = 0;i < objs.length; i++){
			           if (objs[i].checked){
			          	 obj = objs[i];
					    break;
					 }
			     }
			 }else{
				if(objs.checked){
				 obj = objs;
				}
			 }
			
			var data = $(obj).siblings('input[name="datas"]').val().split('@@');
			var partsId = data[1], partsStatus = data[0];
			if(partsStatus==2){
				 pp.$.messager.alert('操作提示',"不可重复操作！","info");
				 return;
			}
			
			pp.openWindow("配件出库",pp.width1,300,"${ctx}/deviceParts/outEdit?partsId="+partsId,[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					doOutStore();
				}
			},{
				text:'取消',
				iconCls:'icon-no',
				handler:function(){
					pp.closeWindow('winDiv2');
				}
			}],'','winDiv2');
		}
		
		function doOutStore(){
			var pp = parent;
			var editFrame = pp.winFrame2;
			if(!pp.validData("useTo","请输入用途！",1,editFrame))
				return;
			
			pp.$.messager.confirm('操作提示','确定要保存吗？',function(r){
			    if (r){
			   	    $.ajax({
						cache: false,
						type: "POST",
						headers: headers,
						url: "${ctx}/deviceParts/saveOut",
						data:editFrame.$('#editForm').serialize(),
						async: false,
					    error: function(request) {
				            pp.$.messager.alert('操作提示',"操作失败！","error");
					    },
					    success: function(data) {
					    	if(data && "success" == data){
					    		pp.$.messager.alert('操作提示',"保存成功！","info",function(){
						         	search();
							         pp.closeWindow('winDiv2');
					         	});
				         	}else{
				         		pp.$.messager.alert('操作提示',"操作失败！","error");
				         	}
					    }
					});
		         }
		     });
		}
		</script>
</html>